package com.hbnu.practices;

/**
 * 在控制台输出所有的水仙花数
 */
public class Practice01 {
    public static void main(String[] args) {
        // 用for实现水仙花数
        flowerNumber1();

        // 用while实现水仙花数
        flowerNumber2();
    }

    private static void flowerNumber2() {
        int i = 100;
        while (i < 1000) {
            int ge = i % 10;
            int shi = i / 10 % 10;
            int bai = i / 100;
            if (i == ge * ge * ge + shi * shi * shi + bai * bai * bai) {
                System.out.println(i);
            }
            i++;
        }
    }

    private static void flowerNumber1() {
        for (int i = 100; i < 1000; i++) {
            int ge = i % 10;
            int shi = i / 10 % 10;
            int bai = i / 100;
            if (i == ge * ge * ge + shi * shi * shi + bai * bai * bai) {
                System.out.println(i);
            }
        }
    }
}
